var mpopup =
{
    context: null,
    constructor: function()
    {
        window.onresize = function () {
            mpopup.show();
        };
    },

    scrollUp: function ()
    {
        window.scrollTo(0,0);
    },

    remove: function ()
    {
        var background = MIOLO_GetElementById('mPopupBackground');
        var popup = MIOLO_GetElementById('mPopup');
        var anchor = MIOLO_GetElementById('mPopupAnchor');

        if ( background && popup && anchor )
        {
            window.setTimeout(function() {
                background.parentNode.removeChild(background);
            }, 200);
            window.setTimeout(function() {
                popup.parentNode.removeChild(popup);
            }, 200);
            window.setTimeout(function() {
                anchor.parentNode.removeChild(anchor);
            }, 200);
        }
    },

    show: function()
    {
        popup  = MIOLO_GetElementById('mPopup');

        if ( popup )
        {
            this.scrollUp();
        }
    },

    configureClose: function()
    {
        MIOLO_GetElementById('mPopupClose').onclick = mpopup.remove;

        document.onkeydown = function ( e )
        {
            if ( e.keyCode == 27 )
            {
                mpopup.remove();
            }
        };
    },

    response: function (result)
    {
        MIOLO_GetElementById('mPopupResponse').innerHTML = result;
        MIOLO_UpdateAJAXValidators('mPopupResponse');
        mpopup.configureClose();
        mpopup.show();

        var script = MIOLO_GetElementById('mPopupResponse').getElementsByTagName('script');
        if ( script.length > 0 )
        {
            for ( var i=0; i < script.length; i++ )
            {
                setTimeout(script[i].innerHTML, 0);
            }
        }
    },

    doAjax: function(url, method)
    {
        MIOLO_ajaxCall(url, "POST", method, '', this.response, "TEXT");
    }
}
